1. Field of the Invention
This invention relates generally to applying texture maps, and more particularly, to a method and apparatus for avoiding processor state transitions while rendering frames.
2. Description of Related Art
Computer graphics systems are commonly used for displaying two-and three-dimensional graphics representations of objects on a two-dimensional video display screen. Current computer graphics systems provide highly detailed representations and are used in a variety of applications, such as computer-aided design, animation and the like.
In a typical computer graphics system, an object or model to be represented on the display screen is broken down into graphics primitives. Primitives are basic components of a graphics display and may include, for example, points, lines, triangles, quadrilaterals, triangle strips and polygons. Typically, a hardware/software scheme is implemented to render, or draw, the graphics primitives that represent a view of one or more objects being represented on the display screen.
Generally, the primitives of a three-dimensional object to be rendered are defined by a host computer in terms of primitive data. For example, when the primitive is a triangle, the host computer may define the primitives in terms of the X, Y, Z and W coordinates of its vertices, as well as the red, green, blue and alpha (R, G, B and alpha.) color values of each vertex. Additional primitive data, such as texture mapping data, may be used in some applications. Rendering hardware interpolates the primitive data to compute the display screen pixels that represent each primitive, and the R, G and B color values for each pixel.
Early graphics systems failed to display images in a sufficiently realistic manner to represent or model complex three-dimensional objects. The images displayed by such systems exhibited extremely smooth surfaces absent textures, bumps, scratches, shadows and other surface details present in the object being modeled.
As a result, methods were developed to display images with improved surface detail. Texture mapping is one such method to improve surface detail that involves mapping a source image, referred to as a texture, onto a surface of a three-dimensional object, and thereafter mapping the textured three-dimensional object to the two-dimensional graphics display screen to display the resulting image. Surface detail attributes commonly texture mapped include color, specular reflection, vector perturbation, specularity, transparency, shadows, surface irregularities and grading. Texture mapping involves applying one or more point elements (texels) of a texture to each point element (pixel) of the displayed portion of the object to which the texture is being mapped. Texture mapping hardware subsystems typically include a local memory cache that stores texture mapping data associated with the portion of the object being rendered.
The basic components of a computer graphics system typically include a host computer and graphics hardware. The host computer may include a graphics application, a graphics application programming interface and a graphics driver. The graphics application programming interface (API) receives commands from a user through the graphics application program and provides primitive data, in conjunction with the graphics driver, to the graphics hardware. The graphics hardware typically includes a geometry accelerator, a rasterizer and a frame buffer, and may include texture mapping hardware. The geometry accelerator receives primitive data from the host computer and performs operations such as coordinate transformations and lighting, clipping and plane equation calculations for each primitive. The output of the geometry accelerator, referred to as rendering data, is used by the rasterizer and the texture mapping hardware to generate final screen coordinate and color data for each pixel in each primitive. The pixel data from the rasterizer and the pixel data from the texture mapping hardware are combined and stored in the frame buffer for display on a display output device such as a monitor, TV or flat panel display.
The applications in the host computer frequently utilizes the OpenGL application programming interface standard. (OpenGL is a registered trademark of Silicon Graphics, Inc.). The OpenGL standard is a hardware independent interface designed to be implemented on different hardware platforms that provides a complete library of low level graphics manipulation commands for describing models of three-dimensional objects. This standard was originally based on the proprietary standards of Silicon Graphics, Inc., but was later transformed into an open standard, which is used in high end graphics-intensive workstations and, more recently, in high end personal computers. OpenGL is supported on a wide range of hardware platforms and software environments such as, Mac(copyright) OS, OS/2(copyright), UNIX, Solaris, Windows 95/98, Windows NT, Linux, OPENStep, Python, and BeOS. The OpenGL standard is described in the OpenGL Programming Guide, Version 1.2 (1999) and the OpenGL Reference Manual, Version 1.1 (1997).
Applications that use texture mapping typically communicate texture map data prior to the start of rendering an image. This is done through glTexImage commands that are issued to the API. To render the image OpenGL commands are passed to the API that specify primitive data and what texture data, if any, is associated with the primitives. Texture map data is associated with a primitive or primitive using the glBindTexture command. A glBindTexture command specifies which texture will be applied to all subsequent primitives until a new texture is specified or texturing is disabled. Typically, the graphics driver processes the OpenGL commands to form a command/data buffer of low level commands according to the graphics hardware implementation. The graphics hardware reads the command/data buffer to render the image.
Before a primitive is rendered, the texture map must be resident on the graphics hardware. Because texture memory is finite, it is possible for the total amount of texture space needed by a graphics application (or multiple applications running simultaneously) to exceed the capacity of the texture memory. This may cause the graphics driver to load and unload textures to ensure that the desired texture is available in texture memory when needed. Thus, if the texture map is not resident in the graphics hardware when the command/data buffer is constructed, the graphics driver will cause the texture map to be loaded into the hardware. This is done by placing the texture data in a separate command/data buffer. The command/data buffer is loaded into the hardware by programming a direct memory access (DMA) engine with the address of the command/data buffer, and the destination address in the graphics hardware.
In Windows NT, all hardware device accesses must occur in privileged mode (or kernel mode). Since the graphics application is running in user mode, a ring transition from user mode to kernel mode is required every time a texture map is loaded. Once processing of the command data buffer has begun by the graphics hardware, the graphics driver returns from kernel mode to user mode to allow the graphics application to continue issuing commands. Depending on the textures loaded and the amount of texture memory, a ring transition is potentially required for every command data buffer. A Windows NT system creates an additional complexity by allowing multiple OpenGL applications to be active simultaneously. The necessity of ring transitions between user and kernal modes are relatively time consuming and reduce system bandwidth. Accordingly, a more efficient method of switching textures is desired.
According to a preferred embodiment, the invention provides a method for rendering textures in a graphics controller. The invention may be broadly conceptualized by the following steps: receiving draw commands from an application; forming a command data buffer responsive to the draw commands containing primitives corresponding to each draw command received from the application; forming a data structure responsive to the draw commands identifying a texture to be applied to the primitives; switching from user mode to kernel mode after forming the command data buffer and the data structure; in kernel mode, loading into the graphics controller a first texture identified in the data structure if the first texture is not present in the graphics controller; and in kernel mode, sending the primitives corresponding to the first texture to the graphics controller. The loading and sending steps may be repeated for each texture identified in the data structure.
Other features and advantages of the invention will become apparent to one of ordinary skill in the art upon examination of the following detailed description of illustrative embodiments in conjunction with the accompanying drawings. It is intended that all such features and advantages be included herein within the scope of the invention and protected by the claims.